/**
 * @see [微信官方文档](https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-camera.html)
 */
export default function start_record(ctx: wx.CameraContext, timeoutCallback?: boolean) {
	if (timeoutCallback === true) {
		return new Promise<{
			msg: {
				tempThumbPath: string;
				tempVideoPath: string;
			};
			success: boolean;
		}>((resolve) => {
			ctx.startRecord({
				success(res) {
					resolve({
						msg: {
							tempThumbPath: res.tempFilePath,
							tempVideoPath: res.tempVideoPath
						},
						success: true
					});
				},
				fail(res) {
					resolve({
						msg: res,
						success: false
					});
				},
				timeoutCallback(res) {
					resolve({
						msg: res,
						success: true
					});
				}
			});
		});
	} else {
		return new Promise<{
			msg: {
				tempThumbPath: string;
				tempVideoPath: string;
			};
			success: boolean;
		}>((resolve) => {
			ctx.startRecord({
				success(res) {
					resolve({
						msg: {
							tempThumbPath: res.tempFilePath,
							tempVideoPath: res.tempVideoPath
						},
						success: true
					});
				},
				fail(res) {
					resolve({
						msg: res,
						success: false
					});
				}
			});
		});
	}

}
